<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /**
       * @param {number[]} digits
       * @return {number[]}
       */
      var plusOne = function (digits) {

        // 倒着遍历
        for(var i=digits.length-1;i>=0;i--) {
          digits[i]+=1
          digits[i] = digits[i] % 10  // 不满10取余不变，满10进1
          if(digits[i] !== 0) {
            return digits
          }
        }
        // 遍历完还没返回说明最大进1
        digits.unshift(1)
        return digits
      };

      var nums = [6,1,4,5,3,9,0,1,9,5,1,8,6,7,0,5,5,4,3];
      console.log(plusOne(nums));
    </script>
  </body>
</html>
